package yb.ecp.fast.user.web;

import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import yb.ecp.fast.infra.infra.ActionResult;
import yb.ecp.fast.infra.infra.PageCommonVO;
import yb.ecp.fast.infra.infra.SearchCommonVO;
import yb.ecp.fast.user.infra.BasicController;
import yb.ecp.fast.user.service.DepartmentService;
import yb.ecp.fast.user.service.ProfileService;
import yb.ecp.fast.user.service.VO.DepartmentVO;
import yb.ecp.fast.user.service.VO.ProfileVO;


/**
 * Created by Xiongcs on 2018/4/6.
 */
@RestController
@RequestMapping("/publicData")
public class PublicDataController extends BasicController {
    @Autowired
    private ProfileService profileService;

    @Autowired
    private DepartmentService departmentService;


    private final String manageSpaceId = "1";

    /**
     * 查询部门列表
     *
     * @param parentId
     * @param name
     * @return
     */
    @RequestMapping(value = "/departmentList", method = RequestMethod.GET)
//    @FastMappingInfo(actionLevel = ActionLevel.INNER)
    public ActionResult departmentList(@RequestParam("parentId") String parentId, @RequestParam("name") String name) {
        DepartmentVO departmentVO = new DepartmentVO();
        departmentVO.setParentId(parentId);
        departmentVO.setName(name);
        departmentVO.setSpaceId(manageSpaceId);
        return actionResult(departmentService.queryDeptList(departmentVO));
    }

    /**
     * 查询部门详细信息
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/departmentDetail", method = RequestMethod.GET)
//    @FastMappingInfo(actionLevel = ActionLevel.INNER)
    public ActionResult departmentDetail(@RequestParam("id") String id) {
        return actionResult(departmentService.item(id));
    }


    @RequestMapping(value = "/userDetail", method = RequestMethod.GET)
//    @FastMappingInfo(actionLevel = ActionLevel.INNER)
    @ApiOperation(value = "查询用户列表详细信息")
    public ActionResult userDetail(@RequestParam("userId") String userId) throws Exception {
        return actionResult(profileService.item(userId));
    }

    @RequestMapping(value = "/userList", method = RequestMethod.POST)
//    @FastMappingInfo(actionLevel = ActionLevel.INNER)
    @ApiOperation(value = "查询用户列表")
    public ActionResult userList(@RequestBody SearchCommonVO<ProfileVO> condition) {
        if (condition.getFilters() == null) {
            condition.setFilters(new ProfileVO());
        }
        condition.getFilters().setSpaceId(manageSpaceId);
        PageCommonVO pageCommonVO = profileService.listAll(condition, null);
        return actionResult(pageCommonVO.getPageInfo());
    }
}
